package com.youlai.boot.system.service.impl;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.boot.system.mapper.SysYouqitouziMapper;
import com.youlai.boot.system.service.SysYouqitouziService;
import com.youlai.boot.system.model.entity.SysYouqitouzi;
import com.youlai.boot.system.model.form.SysYouqitouziForm;
import com.youlai.boot.system.model.query.SysYouqitouziQuery;
import com.youlai.boot.system.model.vo.SysYouqitouziVO;
import com.youlai.boot.system.converter.SysYouqitouziConverter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;

/**
 * 油气项目后评价服务实现类
 *
 * @author 李文兵
 * @since 2025-05-29 11:14
 */
@Service
@RequiredArgsConstructor
public class SysYouqitouziServiceImpl extends ServiceImpl<SysYouqitouziMapper, SysYouqitouzi> implements SysYouqitouziService {

    private final SysYouqitouziConverter sysYouqitouziConverter;

    /**
    * 获取油气项目后评价分页列表
    *
    * @param queryParams 查询参数
    * @return {@link IPage<SysYouqitouziVO>} 油气项目后评价分页列表
    */
    @Override
    public IPage<SysYouqitouziVO> getSysYouqitouziPage(SysYouqitouziQuery queryParams) {
        Page<SysYouqitouziVO> pageVO = this.baseMapper.getSysYouqitouziPage(
                new Page<>(queryParams.getPageNum(), queryParams.getPageSize()),
                queryParams
        );
        return pageVO;
    }
    
    /**
     * 获取油气项目后评价表单数据
     *
     * @param id 油气项目后评价ID
     * @return
     */
    @Override
    public SysYouqitouziForm getSysYouqitouziFormData(Long id) {
        SysYouqitouzi entity = this.getById(id);
        return sysYouqitouziConverter.toForm(entity);
    }
    
    /**
     * 新增油气项目后评价
     *
     * @param formData 油气项目后评价表单对象
     * @return
     */
    @Override
    public boolean saveSysYouqitouzi(SysYouqitouziForm formData) {
        SysYouqitouzi entity = sysYouqitouziConverter.toEntity(formData);
        return this.save(entity);
    }
    
    /**
     * 更新油气项目后评价
     *
     * @param id   油气项目后评价ID
     * @param formData 油气项目后评价表单对象
     * @return
     */
    @Override
    public boolean updateSysYouqitouzi(Long id,SysYouqitouziForm formData) {
        SysYouqitouzi entity = sysYouqitouziConverter.toEntity(formData);
        return this.updateById(entity);
    }
    
    /**
     * 删除油气项目后评价
     *
     * @param ids 油气项目后评价ID，多个以英文逗号(,)分割
     * @return
     */
    @Override
    public boolean deleteSysYouqitouzis(String ids) {
        Assert.isTrue(StrUtil.isNotBlank(ids), "删除的油气项目后评价数据为空");
        // 逻辑删除
        List<Long> idList = Arrays.stream(ids.split(","))
                .map(Long::parseLong)
                .toList();
        return this.removeByIds(idList);
    }

}
